<template>
<div>
  <el-table
    :data="tableData"
    stripe
    style="width: 100%">
    <el-table-column
      prop="id"
      label="编号"
      width="180">
    </el-table-column>
    <el-table-column
      prop="name"
      label="图书名字"
      width="180">
    </el-table-column>
    <el-table-column
      prop="sell"
      label="销售数量"
      width="180">
    </el-table-column>
    <el-table-column
      prop="inferior"
      label="次品数量"
      width="180">
    </el-table-column>
    <el-table-column
      prop="surplus"
      label="剩余数量"
      width="180">
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="primary"
          icon="el-icon-edit"
          @click="dialogFormVisible=true;inventoryupd=scope.row"></el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    small
    layout="total,prev, pager, next"
    :page-size="pageSize"
    :total="total" @current-change="page">
  </el-pagination>

  <el-dialog title="修改" :visible.sync="dialogFormVisible">
    <el-form :model="inventoryupd">
      <el-form-item label="编号">
        <el-input v-model="inventoryupd.id" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="图书名称">
        <el-select v-model="inventoryupd.book" placeholder="请选择类型">
          <el-option v-for="item in findbook" :label="item.name" :key="item.id" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="销售数量">
        <el-input v-model="inventoryupd.sell" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="次品数量">
        <el-input v-model="inventoryupd.inferior" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="剩余数量">
        <el-input v-model="inventoryupd.surplus" autocomplete="off"></el-input>
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="upd()">确 定</el-button>
    </div>
  </el-dialog>
</div>
</template>

<script>
export default {
  name: "Allinventory",
  data(){
    return{
      total: 0,
      pageSize: 6,
      tableData: [],
      inventoryupd:{},
      dialogFormVisible:false,
      findbook:[]
    }
  },
  created() {
    this.find()
    this.findbook1()
  },
  methods:{
    find(){
      this.$http.post("backservice/inventory/findpage?pageNum=0&pageSize=" + this.pageSize).then(response => {
        console.log(response.userList)
        this.tableData = response.userList
        this.total = response.TotalNum
      })
    },
    page(currentPage) {
      this.$http.post('backservice/inventory/findpage?&pageNum=' + (currentPage - 1) + '&pageSize=' + this.pageSize)
        .then(response => {
          this.tableData = response.userList
        })
    },
    findbook1(){
      this.$http.post('backservice/book/find1').then(data=>{
        this.findbook=data;
      })
    },
    upd(){
      this.dialogFormVisible=false
      this.$http.post('backservice/inventory/update',this.inventoryupd).then(data=>{
        if (data>0){
          this.find()
          alert("修改成功")
        }else{
          alert("修改失败")
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
